require 'gtk2'

require 'model'
require 'pages'

class BeanCounterUI
  
  def initialize(prefs)
    @prefs = prefs
    @model = Model.new(@prefs[:data_dir])
    init_vars
    setup_application
    setup_tabs
    @app.show_all
  end
  
  def init_vars
    @tabs = [
      ["Home", HomePage],
      ["Accounts", AccountPage],
      ["Reports", ReportPage],
      ["OFX Data", OfxPage]
    ]
  end
  
  def quit_application
    Gtk.main_quit
  end
  
  def setup_application
    @app = Gtk::Window.new(Gtk::Window::TOPLEVEL)
    @app.title = "Bean.Counter"
    @app.resize(@prefs[:app_window_x], @prefs[:app_window_y])
    @app.maximize if @prefs[:app_window_maximize]
    @app.signal_connect("destroy"){ quit_application }
    @root = Gtk::Notebook.new
    @root.show_border = false
    @app.add(@root)
  end
  
  def setup_tabs
    @tabs.each do |t|
      tab = t[1].new(@model, @prefs)
      @root.append_page(tab, Gtk::Label.new(t[0]))
    end
  end
end

if __FILE__ == $0
  prefs = {
    :data_dir => "../sample_data",
    :home_page_summaries => ["Assets", "Liabilities", "Equity"],
    :account_page_account => "Checking",
    :account_page_list_width => 128,
    :ofx_page_list_width => 256,
    :tool_icon_size => 16,
    :app_window_x => 800,
    :app_window_y => 600,
    :app_window_maximize => false
  }
  BeanCounterUI.new(prefs)
  Gtk.main
end